
//
//  JKViewMineSections.m
//  chequanbao_ios
//
//  Created by 朱凯 on 2018/1/23.
//  Copyright © 2018年 com.itboye. All rights reserved.
//

#import "JKViewMineSections.h"

@implementation JKViewMineSections

- (instancetype)init {
    if (self = [super init]) {
        
        [self setupUI];
    }
    return self;
}
- (void)setupUI {
    
    NSArray *titles = @[@"我是店长", @"商家老板", @"创业伙伴", @"区县服务中心", @"省管理中心"];
    __block UIControl *last = nil;
    [titles enumerateObjectsUsingBlock:^(NSString *title, NSUInteger idx, BOOL * _Nonnull stop) {
        
        UIControl *basalView = [UIControl new];
        basalView.tag = idx;
        [basalView addTarget:self action:@selector(tapAction:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:basalView];
        
        UIImageView *imageView = [UIImageView new];
        imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"我的-%@", title]];
        [basalView addSubview:imageView];
        
        UILabel *label = [[UILabel alloc] init];
        label.adjustsFontSizeToFitWidth = true;
        label.text = title;
        label.font = FONT(15);
        label.textAlignment = NSTextAlignmentCenter;
        label.textColor = [UIColor blackColor];
        [basalView addSubview:label];
        
        
        [basalView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.equalTo(self).multipliedBy(1 / 3.0);
            if (last) {
                // 第一行
                if (idx / 3 == 0) {
                    make.top.equalTo(last);
                    make.left.equalTo(last.mas_right);
                } else {
                    if (idx % 3 == 0) {
                        make.top.equalTo(last.mas_bottom).offset(20);
                        make.left.equalTo(@0);
                    } else {
                        make.top.equalTo(last);
                        make.left.equalTo(last.mas_right);
                    }
                }
            } else {
                make.top.equalTo(@0);
                make.left.equalTo(@0);
            }
            
            // 设置cell的高度
            if (idx == titles.count - 1) {
                make.bottom.equalTo(@0);
            }
        }];
        [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.height.equalTo(@50);
            make.top.equalTo(@10);
            make.centerX.equalTo(@0);
        }];
        [label mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(@0);
            make.top.equalTo(imageView.mas_bottom).offset(10);
            make.height.equalTo(@20);
            // 设置basalView的高度
            make.bottom.equalTo(@-10);
        }];
        
        last = basalView;
    }];
}

- (void)tapAction:(UIControl *)sender {
    
    if (!BY_USER) {
        ByUILoginVC *vc = [[ByUILoginVC alloc] init];
        ByBaseNaviController *navi = [[ByBaseNaviController alloc] initWithRootViewController:vc];
        [((ByBaseVC *)self.viewController) presentViewController:navi animated:YES completion:nil];
        return;
    }

    
    switch (sender.tag) {
        case 0:{
            ByWebViewController *webVC = [[ByWebViewController alloc] initWithTotalUrlString:[NSString stringWithFormat:@"%@extension/index_dxe.html?uid=%@&pwd=%@",BOYE_WEB_BASE_URL,BY_USER.uid,BY_USER.password]];
            webVC.title = @"我是店长";
            [((ByBaseVC *)self.viewController) by_normalPush:webVC hasNavi:YES];
        }
            break;
        case 1:
        {
            NSLog(@"0");
            ByWebViewController *webVC = [[ByWebViewController alloc] initWithTotalUrlString:[NSString stringWithFormat:@"%@extension/index_shop.html?uid=%@&pwd=%@",BOYE_WEB_BASE_URL,BY_USER.uid,BY_USER.password]];
            webVC.title = @"联盟商家";
            [((ByBaseVC *)self.viewController) by_normalPush:webVC hasNavi:YES];
        }
            break;
        case 2:
        {
            NSLog(@"1");
            ByWebViewController *webVC = [[ByWebViewController alloc] initWithTotalUrlString:[NSString stringWithFormat:@"%@extension/index_person.html?uid=%@&pwd=%@",BOYE_WEB_BASE_URL,BY_USER.uid,BY_USER.password]];
            webVC.title = @"创业伙伴";
            [((ByBaseVC *)self.viewController) by_normalPush:webVC hasNavi:YES];
            
        }
            break;
        case 3:
        {
            NSLog(@"2");
            ByWebViewController *webVC = [[ByWebViewController alloc] initWithTotalUrlString:[NSString stringWithFormat:@"%@extension/index_city.html?uid=%@&pwd=%@",BOYE_WEB_BASE_URL,BY_USER.uid,BY_USER.password]];
            webVC.title = @"城市服务中心";
            [((ByBaseVC *)self.viewController) by_normalPush:webVC hasNavi:YES];
        }
            break;
        case 4:
        {
            NSLog(@"3");
            ByWebViewController *webVC = [[ByWebViewController alloc] initWithTotalUrlString:[NSString stringWithFormat:@"%@extension/index_province.html?uid=%@&pwd=%@",BOYE_WEB_BASE_URL,BY_USER.uid,BY_USER.password]];
            webVC.title = @"省管理中心";
            [((ByBaseVC *)self.viewController) by_normalPush:webVC hasNavi:YES];
        }
            break;
            
        default:
            break;
    }
}

@end
